在工作流中的activiti的serviceTask几种方法:
模拟自动执行任务工作流的流程图:
![点击查看原始大小图片](http://topmanopensource.iteye.com/upload/picture/pic/104736/d08be1ae-15fa-3d16-8256-be97c16a2cf7.jpg)
工作流配置:
serviceTaskExpression.bpmn20.xml
Xml代码
Welcome to Beijing Hello Mr. Bai
工作流的实现:
Java代码
package com.easyway.activiti.servicetask; import org.activiti.engine.delegate.DelegateExecution; /** * 从配置文件注入多个属性类型必须为Expression * @author longgangbai * * 2011-12-20 下午10:08:01 */ public class ReverseStringsFieldInjected implements JavaDelegate { private Expression text1; private Expression text2; public void execute(DelegateExecution execution) { String value1 = (String) text1.getValue(execution); execution.setVariable("var1", new StringBuffer(value1).reverse().toString()); String value2 = (String) text2.getValue(execution); execution.setVariable("var2", new StringBuffer(value2).reverse().toString()); } }
Java代码
package com.easyway.activiti.servicetask; import org.activiti.engine.delegate.DelegateExecution; /** * 从配置文件注入一个字符串用于变为写 * @author longgangbai * * 2011-12-20 下午09:56:59 */ public class ToUppercase implements JavaDelegate { private Expression text; public void execute(DelegateExecution execution) throws Exception { String value1 = (String) text.getValue(execution); execution.setVariable("input", value1); } }
servicetaskSpringTest-context.xml
Xml代码
测试类:
Java代码
package com.easyway.activiti.servicetask; import org.activiti.engine.runtime.ProcessInstance; import org.activiti.engine.test.Deployment; import org.activiti.spring.impl.test.SpringActivitiTestCase; import org.springframework.test.context.ContextConfiguration; /** * 工作流中ServiceTask的各种方法 * 1.通过activiti:class使用相关的javaDelegate的子类。 * Welcome to Beijing Hello Mr. Bai 2.通过spring的使用委派表达式实现 3.通过表达式将实现 4.通过activiti:class注入相关的属性 * @author longgangbai * * 2011-12-20 下午09:29:23 */ @ContextConfiguration("classpath:servicetaskSpringTest-context.xml") public class ServiceTaskExpressionTest extends SpringActivitiTestCase { @Deployment(resources={"diagrams/serviceTaskExpression.bpmn20.xml"}) public void testDelegateExpression() { ProcessInstance procInst = runtimeService.startProcessInstanceByKey("serviceTaskProcess"); assertEquals(true,procInst.isEnded()); } }
原文地址:http://topmanopensource.iteye.com/blog/1319380
|